#include "tcpserver.h"
#include "ui_tcpserver.h"
#include "mytcpserver.h"
#include <QDebug>
#include <QMessageBox>
#include <QFile>
// #include "opedb.h"

TcpServer::TcpServer(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::TcpServer)
{
    ui->setupUi(this);

    this->loadConfig();
    MyTcpServer::getInstance().listen(QHostAddress(m_ip), m_port);

    //OpeDB::getInstence();
}

TcpServer::~TcpServer()
{
    delete ui;
}

void TcpServer::loadConfig()
{
    QFile file(":/server.config");
    if (file.open(QIODevice::ReadOnly)) {
        QByteArray ba_data = file.readAll();
        QString str_data = ba_data.toStdString().c_str();
        file.close();
        QStringList str_list = str_data.split("\n");
        m_ip = str_list[0];
        m_port = str_list[1].toUShort();
        // qDebug() << m_ip << "-" << m_port ;

    } else
        QMessageBox::critical(this, "open file", "open file failed");
}
